package com.qr.service.wmyw.impl;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.mapping.ResultMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.krui.helper.db.DBHelper;
import cn.krui.helper.db.DataPage;
import com.qr.bean.wmyw.QrOrderTakeout;
import com.qr.bean.wmyw.QrOrderTakeoutView;
import com.qr.controller.WmywBase;
import com.qr.mapper.wmyw.QrOrderTakeoutMapper;
import com.qr.mapper.wmyw.QrOrderTakeoutMapperView;
import com.qr.service.wmyw.QrOrderTakeoutService;
//import org.apache.dubbo.config.annotation.Service;

/**
 * @author: zc
 * email: zc8023zs@163.com
 * create_time: 2020/8/13 10:24:14
 */
@Service
//@Service(version = "1.0.0",group="dubbo")
public class QrOrderTakeoutServiceImpl implements QrOrderTakeoutService{
    @Autowired
    private QrOrderTakeoutMapper qrOrderTakeoutMapper;

    @Autowired
    private QrOrderTakeoutMapperView qrOrderTakeoutMapperView;
    
    @Autowired
    private DBHelper dbHelper;

    /**
     * 构造查询条件
     */
    private QueryWrapper<QrOrderTakeout> InitWrapper(QrOrderTakeout where){
        QueryWrapper<QrOrderTakeout> whereWrapper = new QueryWrapper<QrOrderTakeout>();
        if(where.getOrder_id()!=null){
			whereWrapper.eq("order_id",where.getOrder_id());
		}
        if(where.getOc_id()!=null){
			whereWrapper.eq("oc_id",where.getOc_id());
		}
        if(where.getShop_id()!=null){
			whereWrapper.eq("shop_id",where.getShop_id());
		}
        if(where.getUid()!=null){
			whereWrapper.eq("uid",where.getUid());
		}
        if(where.getGoods_num()!=null){
			whereWrapper.eq("goods_num",where.getGoods_num());
		}
        if(where.getOrder_no()!=null){
			whereWrapper.eq("order_no",where.getOrder_no());
		}
        if(where.getNo_order()!=null){
			whereWrapper.eq("no_order",where.getNo_order());
		}
        if(where.getOrder_pickno()!=null){
			whereWrapper.eq("order_pickno",where.getOrder_pickno());
		}
        if(where.getOrder_status()!=null){
			whereWrapper.eq("order_status",where.getOrder_status());
		}
        if(where.getDelivery_status()!=null){
			whereWrapper.eq("delivery_status",where.getDelivery_status());
		}
        if(where.getExpress_no()!=null){
			whereWrapper.eq("express_no",where.getExpress_no());
		}
        if(where.getConsigne()!=null){
			whereWrapper.eq("consigne",where.getConsigne());
		}
        if(where.getTel()!=null){
			whereWrapper.eq("tel",where.getTel());
		}
        if(where.getProvince()!=null){
			whereWrapper.eq("province",where.getProvince());
		}
        if(where.getCity()!=null){
			whereWrapper.eq("city",where.getCity());
		}
        if(where.getDistrict()!=null){
			whereWrapper.eq("district",where.getDistrict());
		}
        if(where.getAddress()!=null){
			whereWrapper.eq("address",where.getAddress());
		}
        if(where.getFull_address()!=null){
			whereWrapper.eq("full_address",where.getFull_address());
		}
        if(where.getLng()!=null){
			whereWrapper.eq("lng",where.getLng());
		}
        if(where.getLat()!=null){
			whereWrapper.eq("lat",where.getLat());
		}
        if(where.getOriginal_amount()!=null){
			whereWrapper.eq("original_amount",where.getOriginal_amount());
		}
        if(where.getPackage_amount()!=null){
			whereWrapper.eq("package_amount",where.getPackage_amount());
		}
        if(where.getDelivery_amount()!=null){
			whereWrapper.eq("delivery_amount",where.getDelivery_amount());
		}
        if(where.getCoupon_amount()!=null){
			whereWrapper.eq("coupon_amount",where.getCoupon_amount());
		}
        if(where.getCoupon_id()!=null){
			whereWrapper.eq("coupon_id",where.getCoupon_id());
		}
        if(where.getOff_amount()!=null){
			whereWrapper.eq("off_amount",where.getOff_amount());
		}
        if(where.getAmount()!=null){
			whereWrapper.eq("amount",where.getAmount());
		}
        if(where.getPay_no()!=null){
			whereWrapper.eq("pay_no",where.getPay_no());
		}
        if(where.getPay_gateway()!=null){
			whereWrapper.eq("pay_gateway",where.getPay_gateway());
		}
        if(where.getNote()!=null){
			whereWrapper.eq("note",where.getNote());
		}
        if(where.getTableware()!=null){
			whereWrapper.eq("tableware",where.getTableware());
		}
        if(where.getDelivery_gateway()!=null){
			whereWrapper.eq("delivery_gateway",where.getDelivery_gateway());
		}
        if(where.getDelivery_no()!=null){
			whereWrapper.eq("delivery_no",where.getDelivery_no());
		}
        if(where.getDelivery_name()!=null){
			whereWrapper.eq("delivery_name",where.getDelivery_name());
		}
        if(where.getDelivery_mobile()!=null){
			whereWrapper.eq("delivery_mobile",where.getDelivery_mobile());
		}
        if(where.getTime_create()!=null){
			whereWrapper.eq("time_create",where.getTime_create());
		}
        if(where.getTime_pay()!=null){
			whereWrapper.eq("time_pay",where.getTime_pay());
		}
        if(where.getTime_user_plan_receiving()!=null){
			whereWrapper.eq("time_user_plan_receiving",where.getTime_user_plan_receiving());
		}
        if(where.getTime_shop_receiving()!=null){
			whereWrapper.eq("time_shop_receiving",where.getTime_shop_receiving());
		}
        if(where.getTime_rider_receiving()!=null){
			whereWrapper.eq("time_rider_receiving",where.getTime_rider_receiving());
		}
        if(where.getTime_shop_package()!=null){
			whereWrapper.eq("time_shop_package",where.getTime_shop_package());
		}
        if(where.getTime_rider_arrive()!=null){
			whereWrapper.eq("time_rider_arrive",where.getTime_rider_arrive());
		}
        if(where.getTime_rider_package()!=null){
			whereWrapper.eq("time_rider_package",where.getTime_rider_package());
		}
        if(where.getTime_shop_finish()!=null){
			whereWrapper.eq("time_shop_finish",where.getTime_shop_finish());
		}
        if(where.getTime_rider_finish()!=null){
			whereWrapper.eq("time_rider_finish",where.getTime_rider_finish());
		}
        if(where.getTime_user_finish()!=null){
			whereWrapper.eq("time_user_finish",where.getTime_user_finish());
		}
        if(where.getTime_user_cancel()!=null){
			whereWrapper.eq("time_user_cancel",where.getTime_user_cancel());
		}
        if(where.getTime_shop_audit()!=null){
			whereWrapper.eq("time_shop_audit",where.getTime_shop_audit());
		}
        if(where.getTime_user_reput()!=null){
			whereWrapper.eq("time_user_reput",where.getTime_user_reput());
		}
        if(where.getTime_platform_finish()!=null){
			whereWrapper.eq("time_platform_finish",where.getTime_platform_finish());
		}
        if(where.getRefund_amount()!=null){
			whereWrapper.eq("refund_amount",where.getRefund_amount());
		}
        if(where.getNote_user()!=null){
			whereWrapper.eq("note_user",where.getNote_user());
		}
        if(where.getCertificate_user()!=null){
			whereWrapper.eq("certificate_user",where.getCertificate_user());
		}
        if(where.getNote_shop()!=null){
			whereWrapper.eq("note_shop",where.getNote_shop());
		}
        if(where.getCetificate_shop()!=null){
			whereWrapper.eq("cetificate_shop",where.getCetificate_shop());
		}
        if(where.getNote_rider()!=null){
			whereWrapper.eq("note_rider",where.getNote_rider());
		}
        if(where.getCetificate_rider()!=null){
			whereWrapper.eq("cetificate_rider",where.getCetificate_rider());
		}
        if(where.getRefund_no()!=null){
			whereWrapper.eq("refund_no",where.getRefund_no());
		}
        if(where.getSettlement_status()!=null){
			whereWrapper.eq("settlement_status",where.getSettlement_status());
		}
        if(where.getSettlement_time()!=null){
			whereWrapper.eq("settlement_time",where.getSettlement_time());
		}
        if(where.getVersion_id()!=null){
			whereWrapper.eq("version_id",where.getVersion_id());
		}
        return whereWrapper;
    }

    private QueryWrapper<QrOrderTakeoutView> InitWrapperView(QrOrderTakeoutView where){
        QueryWrapper<QrOrderTakeoutView> whereWrapper = new QueryWrapper<QrOrderTakeoutView>();
        if(where.getOrder_id()!=null){
			whereWrapper.eq("order_id",where.getOrder_id());
		}
        if(where.getOc_id()!=null){
			whereWrapper.eq("oc_id",where.getOc_id());
		}
        if(where.getShop_id()!=null){
			whereWrapper.eq("shop_id",where.getShop_id());
		}
        if(where.getUid()!=null){
			whereWrapper.eq("uid",where.getUid());
		}
        if(where.getGoods_num()!=null){
			whereWrapper.eq("goods_num",where.getGoods_num());
		}
        if(where.getOrder_no()!=null){
			whereWrapper.eq("order_no",where.getOrder_no());
		}
        if(where.getNo_order()!=null){
			whereWrapper.eq("no_order",where.getNo_order());
		}
        if(where.getOrder_pickno()!=null){
			whereWrapper.eq("order_pickno",where.getOrder_pickno());
		}
        if(where.getOrder_status()!=null){
			whereWrapper.eq("order_status",where.getOrder_status());
		}
        if(where.getDelivery_status()!=null){
			whereWrapper.eq("delivery_status",where.getDelivery_status());
		}
        if(where.getExpress_no()!=null){
			whereWrapper.eq("express_no",where.getExpress_no());
		}
        if(where.getConsigne()!=null){
			whereWrapper.eq("consigne",where.getConsigne());
		}
        if(where.getTel()!=null){
			whereWrapper.eq("tel",where.getTel());
		}
        if(where.getProvince()!=null){
			whereWrapper.eq("province",where.getProvince());
		}
        if(where.getCity()!=null){
			whereWrapper.eq("city",where.getCity());
		}
        if(where.getDistrict()!=null){
			whereWrapper.eq("district",where.getDistrict());
		}
        if(where.getAddress()!=null){
			whereWrapper.eq("address",where.getAddress());
		}
        if(where.getFull_address()!=null){
			whereWrapper.eq("full_address",where.getFull_address());
		}
        if(where.getLng()!=null){
			whereWrapper.eq("lng",where.getLng());
		}
        if(where.getLat()!=null){
			whereWrapper.eq("lat",where.getLat());
		}
        if(where.getOriginal_amount()!=null){
			whereWrapper.eq("original_amount",where.getOriginal_amount());
		}
        if(where.getPackage_amount()!=null){
			whereWrapper.eq("package_amount",where.getPackage_amount());
		}
        if(where.getDelivery_amount()!=null){
			whereWrapper.eq("delivery_amount",where.getDelivery_amount());
		}
        if(where.getCoupon_amount()!=null){
			whereWrapper.eq("coupon_amount",where.getCoupon_amount());
		}
        if(where.getCoupon_id()!=null){
			whereWrapper.eq("coupon_id",where.getCoupon_id());
		}
        if(where.getOff_amount()!=null){
			whereWrapper.eq("off_amount",where.getOff_amount());
		}
        if(where.getAmount()!=null){
			whereWrapper.eq("amount",where.getAmount());
		}
        if(where.getPay_no()!=null){
			whereWrapper.eq("pay_no",where.getPay_no());
		}
        if(where.getPay_gateway()!=null){
			whereWrapper.eq("pay_gateway",where.getPay_gateway());
		}
        if(where.getNote()!=null){
			whereWrapper.eq("note",where.getNote());
		}
        if(where.getTableware()!=null){
			whereWrapper.eq("tableware",where.getTableware());
		}
        if(where.getDelivery_gateway()!=null){
			whereWrapper.eq("delivery_gateway",where.getDelivery_gateway());
		}
        if(where.getDelivery_no()!=null){
			whereWrapper.eq("delivery_no",where.getDelivery_no());
		}
        if(where.getDelivery_name()!=null){
			whereWrapper.eq("delivery_name",where.getDelivery_name());
		}
        if(where.getDelivery_mobile()!=null){
			whereWrapper.eq("delivery_mobile",where.getDelivery_mobile());
		}
        if(where.getTime_create()!=null){
			whereWrapper.eq("time_create",where.getTime_create());
		}
        if(where.getTime_pay()!=null){
			whereWrapper.eq("time_pay",where.getTime_pay());
		}
        if(where.getTime_user_plan_receiving()!=null){
			whereWrapper.eq("time_user_plan_receiving",where.getTime_user_plan_receiving());
		}
        if(where.getTime_shop_receiving()!=null){
			whereWrapper.eq("time_shop_receiving",where.getTime_shop_receiving());
		}
        if(where.getTime_rider_receiving()!=null){
			whereWrapper.eq("time_rider_receiving",where.getTime_rider_receiving());
		}
        if(where.getTime_shop_package()!=null){
			whereWrapper.eq("time_shop_package",where.getTime_shop_package());
		}
        if(where.getTime_rider_arrive()!=null){
			whereWrapper.eq("time_rider_arrive",where.getTime_rider_arrive());
		}
        if(where.getTime_rider_package()!=null){
			whereWrapper.eq("time_rider_package",where.getTime_rider_package());
		}
        if(where.getTime_shop_finish()!=null){
			whereWrapper.eq("time_shop_finish",where.getTime_shop_finish());
		}
        if(where.getTime_rider_finish()!=null){
			whereWrapper.eq("time_rider_finish",where.getTime_rider_finish());
		}
        if(where.getTime_user_finish()!=null){
			whereWrapper.eq("time_user_finish",where.getTime_user_finish());
		}
        if(where.getTime_user_cancel()!=null){
			whereWrapper.eq("time_user_cancel",where.getTime_user_cancel());
		}
        if(where.getTime_shop_audit()!=null){
			whereWrapper.eq("time_shop_audit",where.getTime_shop_audit());
		}
        if(where.getTime_user_reput()!=null){
			whereWrapper.eq("time_user_reput",where.getTime_user_reput());
		}
        if(where.getTime_platform_finish()!=null){
			whereWrapper.eq("time_platform_finish",where.getTime_platform_finish());
		}
        if(where.getRefund_amount()!=null){
			whereWrapper.eq("refund_amount",where.getRefund_amount());
		}
        if(where.getNote_user()!=null){
			whereWrapper.eq("note_user",where.getNote_user());
		}
        if(where.getCertificate_user()!=null){
			whereWrapper.eq("certificate_user",where.getCertificate_user());
		}
        if(where.getNote_shop()!=null){
			whereWrapper.eq("note_shop",where.getNote_shop());
		}
        if(where.getCetificate_shop()!=null){
			whereWrapper.eq("cetificate_shop",where.getCetificate_shop());
		}
        if(where.getNote_rider()!=null){
			whereWrapper.eq("note_rider",where.getNote_rider());
		}
        if(where.getCetificate_rider()!=null){
			whereWrapper.eq("cetificate_rider",where.getCetificate_rider());
		}
        if(where.getRefund_no()!=null){
			whereWrapper.eq("refund_no",where.getRefund_no());
		}
        if(where.getSettlement_status()!=null){
			whereWrapper.eq("settlement_status",where.getSettlement_status());
		}
        if(where.getSettlement_time()!=null){
			whereWrapper.eq("settlement_time",where.getSettlement_time());
		}
        if(where.getVersion_id()!=null){
			whereWrapper.eq("version_id",where.getVersion_id());
		}
        return whereWrapper;
    }

    /**
     * 订单表新增
     * @param model 订单表实体
     * @return 影响行数
     */
	@Override
    public Integer add(QrOrderTakeout model){
        return qrOrderTakeoutMapper.insert(model);
    }

    /**
     * 订单表修改byid
     * @param model 订单表实体
     * @return 影响行数
     */
	@Override
    public Integer update(QrOrderTakeout model) {
        return qrOrderTakeoutMapper.updateById(model);
    }

    /**
     * 订单表修改by条件
     * @param model 订单表实体
     * @param where 订单表条件
     * @return 影响行数
     */
	@Override
    public Integer update(QrOrderTakeout model, Wrapper<QrOrderTakeout> where) {
        return qrOrderTakeoutMapper.update(model, where);
    }

    /**
     * 订单表修改by条件-自动封装Wrapper
     * @param model 订单表实体
     * @return 影响行数
     */
	@Override
    public Integer update(QrOrderTakeout model, QrOrderTakeout where) {
        Wrapper<QrOrderTakeout> wrapper = InitWrapper(where);
        return update(model, wrapper);
    }

    /**
     * 订单表修改bySQL *version_id = newVersion where version_id = oldVersion
     * @param fields 修改的数据 col1=xx,col2=yy
     * @param where 参数化条件 col1=#{col1}
     * @param params 条件参数 col1=xx
     * @return 影响行数
     */
	@Override
    public Integer update(Map<String, Object> fields, String where, Map<String, Object> params) {
        return dbHelper.update("qr_order_takeout", fields, where, params);
    }

    /**
     * 订单表删除byid
     * @param id 订单表主键
     * @return 影响行数
     */
	@Override
    public Integer del(int id) {
        return qrOrderTakeoutMapper.deleteById(id);
    }

    /**
     * 订单表删除by条件
     * @param where 订单表条件
     * @return 影响行数
     */
	@Override
    public Integer del(Wrapper<QrOrderTakeout> where) {
        return qrOrderTakeoutMapper.delete(where);
    }

    /**
     * 订单表删除by条件-自动封装Wrapper
     * @param where 订单表条件
     * @return 影响行数
     */
    @Override
    public Integer del(QrOrderTakeout where) { 
        Wrapper<QrOrderTakeout> wrapper = InitWrapper(where);
        return del(wrapper);
    }

    /**
     * 订单表批量删除byid
     * @param ids 订单表主键集合
     * @return 影响行数
     */
	@Override
    public Integer del(List<Integer> ids){
        return qrOrderTakeoutMapper.deleteBatchIds(ids);
    }

    /**
     * 订单表批量删除bymap条件
     * @param map 订单表map条件
     * @return 影响行数
     */
	@Override
    public Integer del(Map<String,Object> map){
        return qrOrderTakeoutMapper.deleteByMap(map);
    }

    /**
     * 订单表详情byid
     * @param id 订单表主键
     * @return 订单表详情
     */
	@Override
    public QrOrderTakeoutView info(int id){
        return qrOrderTakeoutMapperView.selectById(id);
    }

    /**
     * 订单表详情by条件
     * @param where 订单表条件
     * @return 订单表详情
     */
	@Override
    public QrOrderTakeoutView info(Wrapper<QrOrderTakeoutView> where){
        return qrOrderTakeoutMapperView.selectOne(where);
    }

    /**
     * 订单表详情by条件-自动封装Wrapper
     * @param where 订单表条件
     * @return 订单表详情
     */
	@Override
    public QrOrderTakeoutView info(QrOrderTakeoutView where) {
        Wrapper<QrOrderTakeoutView> wrapper = InitWrapperView(where);
        return info(wrapper);
    }

    /**
     * 订单表详情bySQL
     * @param columns  列名col1,col2,col3^
     * @param where 条件 col1=#{col1}
     * @param params col1:xx
     * @param mappings col1->col1
     * @return
     */
	@Override
    public QrOrderTakeout info(String columns, String where, Map<String, Object> params, ResultMapping mappings) {
        return dbHelper.selectOne(columns, "qr_order_takeout", where, params, QrOrderTakeout.class, mappings);
    }

    /**
     * 订单表批量查询byid
     * @param ids 订单表主键集合
     * @return 订单表列表
     */
	@Override
    public List<QrOrderTakeoutView> select(List<Integer> ids){
        return qrOrderTakeoutMapperView.selectBatchIds(ids);
    }

    /**
     * 订单表批量查询by条件
     * @param where 订单表条件
     * @return 订单表列表
     */
	@Override
    public List<QrOrderTakeoutView> select(Wrapper<QrOrderTakeoutView> where){
        return qrOrderTakeoutMapperView.selectList(where);
    }

    /**
     * 订单表批量查询by条件-自动封装Wrapper
     * @param where 订单表条件
     * @return 订单表列表
     */
    @Override
    public List<QrOrderTakeoutView> select(QrOrderTakeoutView where) {
        Wrapper<QrOrderTakeoutView> wrapper = InitWrapperView(where);		
        return select(wrapper);
    }

    /**
     * 订单表批量查询bymap条件
     * @param map 订单表map条件
     * @return 订单表列表
     */
	@Override
    public List<QrOrderTakeoutView> select(Map<String,Object> map){
        return qrOrderTakeoutMapperView.selectByMap(map);
    }

    /**
     * 订单表批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
	@Override
    public IPage<QrOrderTakeoutView> select(IPage<QrOrderTakeoutView> page, Wrapper<QrOrderTakeoutView> where){
        return qrOrderTakeoutMapperView.selectPage(page, where);
    }

    /**
     * 订单表批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
    @Override
    public IPage<QrOrderTakeoutView> select(IPage<QrOrderTakeoutView> page, QrOrderTakeoutView where) {
		Wrapper<QrOrderTakeoutView> wrapper = InitWrapperView(where);		
        return select(page, wrapper);
    }

    /**
     * 订单表查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(Wrapper<QrOrderTakeoutView> where){
        return qrOrderTakeoutMapperView.selectCount(where);
    }

    /**
     * 订单表查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(QrOrderTakeoutView where){
		Wrapper<QrOrderTakeoutView> wrapper = InitWrapperView(where);
        return selectCount(wrapper);
    }

    /**
     * 订单表批量查询bySQL条件分页
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param orderBy 排序字段
     * @param params 参数化 col1=xx
     * @param pageNumber 分页页码
     * @param pageSize 每页行数
     * @param mappings 查询列和实体映射
     * @return 分页之后的数据含总行数
     */
	@Override
    public DataPage<QrOrderTakeoutView> select(String columns, String where, String orderBy, Map<String, Object> params, int pageNumber, int pageSize, ResultMapping mappings){
        return dbHelper.select(columns, "qr_order_takeout", where, orderBy, params, pageNumber, pageSize, QrOrderTakeoutView.class,mappings);
    }

    /**
     * 订单表批量查询bySQL条件
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param params 参数化 col1=xx
     * @param mappings 查询列和实体映射
     * @return 栏目扩展列表
     */
	@Override
    public List<QrOrderTakeoutView> select(String columns, String where, Map<String, Object> params, ResultMapping mappings){
        return dbHelper.select(columns,"qr_order_takeout",where,params,QrOrderTakeoutView.class,mappings);
    }
}